package cn.lonecloud.action.product;

import cn.lonecloud.model.Product;
import cn.lonecloud.model.User;
import cn.lonecloud.service.ProductService;
import cn.lonecloud.service.impl.ProductServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

/**
 * @author lonecloud
 * 保存产品信息
 */
@WebServlet("/saveProduct")
public class SaveProductServlet extends HttpServlet{
	protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException ,java.io.IOException {
		ProductService productService = new ProductServiceImpl();
		String name = req.getParameter("name");
		String description = req.getParameter("description");
		String count = req.getParameter("count");
		Product product = new Product();
		product.setName(name);
		product.setDescription(description);
		product.setCount(Integer.parseInt(count));
		product.setOwn((User)req.getSession().getAttribute("user"));
		productService.save(product);
		resp.sendRedirect("main");
	};
}
